package com.cuitrip.apiservice;

import android.text.TextUtils;

import com.alibaba.fastjson.TypeReference;
import com.cuitrip.apiservice.model.ApiManager;
import com.cuitrip.business.home.recommend.model.Category;
import com.cuitrip.business.home.recommend.model.HomeCard;
import com.cuitrip.business.home.recommend.model.ListResponse;
import com.cuitrip.business.home.travel.model.FilterExp;
import com.cuitrip.business.home.travel.model.SelectInfo;
import com.cuitrip.business.home.trip.model.RecommendOutData;
import com.cuitrip.business.login.LoginInstance;
import com.cuitrip.business.pay.model.PayMode;
import com.cuitrip.business.tripservice.model.CategoryInfo;
import com.lab.network.config.CachePolicyEnum;
import com.lab.network.model.CtApiRequest;
import com.lab.network.model.CtRemoteBusiness;
import com.lab.network.model.ParseType;
import com.lab.network.model.ResultType;
import com.lab.network.proxy.ApiProxy;

public class TripBusiness {

    public static final String USER_TYPE = "user";

    public static final String SERVICE_TYPE = "service";

    public static void getRecommendCardList(ApiProxy apiProxy, boolean useCache,
                                            int start, int size) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.RECOMMEND_CARD);
        ctApiRequest.addParam("start", String.valueOf(start));
        ctApiRequest.addParam("size", String.valueOf(size));
        ctApiRequest.addParam("order", "desc");
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        if (useCache) {
            ctRemoteBusiness.useCache(CachePolicyEnum.RequestUseCacheWhenExpireReload);
        }
        apiProxy.postAsync(ctRemoteBusiness, new ParseType(new TypeReference<ListResponse<HomeCard>>() {
        }.getType()));
    }

    public static void getRecommendCategoryList(ApiProxy apiProxy) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.GET_HOT_CATES);
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        apiProxy.postAsync(ctRemoteBusiness, new ParseType(ResultType.ARRAY, Category.class));
    }

    public static void getTravelTripList(ApiProxy apiProxy,
                                         String keyword, int start, int size, String from, String sortMethod, SelectInfo selectInfo) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.SERVICE_SEARCH);
        if (LoginInstance.getInstance().getUserInfo() != null
                && !TextUtils.isEmpty(LoginInstance.getInstance().getUserInfo().getUid())) {
            ctApiRequest.addParam("uid", LoginInstance.getInstance().getUserInfo().getUid());
        }

        if (!TextUtils.isEmpty(keyword)) {
            ctApiRequest.addParam("keyWord", keyword);
        }
        if (!TextUtils.isEmpty(from)) {
            ctApiRequest.addParam("from", from);
        }
        if (!TextUtils.isEmpty(sortMethod)) {
            ctApiRequest.addParam("sort", sortMethod);
        }
        ctApiRequest.addParam("start", start);
        ctApiRequest.addParam("size", size);
        if (selectInfo != null) {
            ctApiRequest.addParam("filter", selectInfo.toFilterJSON());
            String cityAbbr = selectInfo.getCityAbbr();
            if (!TextUtils.isEmpty(cityAbbr)) {
                ctApiRequest.addParam("cityAbbr", cityAbbr);
            }
        }
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        apiProxy.postAsync(ctRemoteBusiness, new ParseType(RecommendOutData.class));
    }

    public static void likeService(ApiProxy apiProxy, String sid, String serviceName, String serviceAddress, String servicePic
            , String insiderId, String insiderNick, String insiderPic, String insiderCarrer) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.ADD_LIKE);
        ctApiRequest.addParam("sid", sid);
        ctApiRequest.addParam("type", "1");
        ctApiRequest.addParam("serviceName", serviceName);
        ctApiRequest.addParam("serviceAddress", serviceAddress);
        ctApiRequest.addParam("servicePic", servicePic);
        ctApiRequest.addParam("insiderId", insiderId);
        ctApiRequest.addParam("insiderNick", insiderNick);
        ctApiRequest.addParam("insiderPic", insiderPic);
        ctApiRequest.addParam("insiderCarrer", insiderCarrer);
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        apiProxy.postAsync(ctRemoteBusiness, new ParseType());
    }

    public static void unlikeService(ApiProxy apiProxy, String sid) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.ADD_LIKE);
        ctApiRequest.addParam("sid", sid);
        ctApiRequest.addParam("type", "2");
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        apiProxy.postAsync(ctRemoteBusiness, new ParseType());
    }

    public static void getLikes(ApiProxy apiProxy, int start, int size) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.GET_LIKES);
        ctApiRequest.addParam("start", start);
        ctApiRequest.addParam("size", size);
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        apiProxy.postAsync(ctRemoteBusiness, new ParseType(RecommendOutData.class));
    }

    public static void getTripCates(ApiProxy apiProxy, String cateIds) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.GET_TRIP_CATES);
        ctApiRequest.addParam("cateIds", cateIds);
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        apiProxy.postAsync(ctRemoteBusiness, new ParseType(ResultType.ARRAY, CategoryInfo.class));
    }

    public static ApiProxy.ApiProxyResult getSyncTripCategories(ApiProxy apiProxy, String cateIds) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.GET_TRIP_CATES);
        ctApiRequest.addParam("cateIds", cateIds);
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        return apiProxy.postSync(ctRemoteBusiness, new ParseType(ResultType.ARRAY, CategoryInfo.class));
    }

    public static void getSearchNaviParm(ApiProxy apiProxy) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.GET_SEARCH_NAVI_PRAM);
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        apiProxy.postAsync(ctRemoteBusiness, new ParseType(FilterExp.class));
    }

    public static void getInfoPages(ApiProxy apiProxy, String type) {
        CtApiRequest ctApiRequest = new CtApiRequest();
        ctApiRequest.setApiName(ApiManager.GET_INFOPAGES);
        ctApiRequest.addParam("type", type);
        CtRemoteBusiness ctRemoteBusiness = new CtRemoteBusiness(ctApiRequest);
        //apiProxy.postAsync(ctRemoteBusiness, new ParseType(ResultType.ARRAY,FeeDescription.class));
        apiProxy.postAsync(ctRemoteBusiness, new ParseType(PayMode.class));
    }
}
